package com.et.machine.manager.vm.setting;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.et.machine.R;
import com.et.machine.databinding.DialogSettingTemperatureBinding;

public class SetTemperatureDialog extends Dialog {
    private OnDialogListener customDialogListener;
    private DialogSettingTemperatureBinding binding;
    private String temperature;


    public SetTemperatureDialog(Context context, String temperature, OnDialogListener customDialogListener) {
        super(context, R.style.common_dialog);
        this.customDialogListener = customDialogListener;
        this.temperature = temperature;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DialogSettingTemperatureBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.number.setText(temperature);
        binding.number.setSelection(0, binding.number.getText().length());
        binding.ensure.setOnClickListener(ensure_clickListener);
        binding.cancel.setOnClickListener(cancel_clickListener);
    }

    //发送消息,回调函数取值;
    private View.OnClickListener ensure_clickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            customDialogListener.back(binding.number.getText().toString());
            SetTemperatureDialog.this.dismiss();
        }
    };

    //取消发送;
    private View.OnClickListener cancel_clickListener = v -> {
        SetTemperatureDialog.this.dismiss();  //关闭提示框
    };

    //定义回调事件，用于dialog的点击后的处理事件
    public interface OnDialogListener {
        void back(String temperature);
    }

}
